// import calculator from '../product/productdetail.js';

require(['../config'], function () {
	require(['jquery', 'avalon', 'util', 'Cookies', 'text!/common/nav.html', 'text!/common/footer.html', 'navInit'], function ($, avalon, util, Cookies,
		navHtml,
		footerHtml,
		navInit) {

		$(".global-nav").html(navHtml);
		$(".global-footer").html(footerHtml);
		navInit();

		var professional = util.getUrlParam('professional');
		var salary = util.getUrlParam('salary');
		var assetType = util.getUrlParam('assetType');

		var carType = 1;
		var houseType = 1;
		// assetType is not beshould
		// 0 has 1 not has

		switch (parseInt(assetType)) {
			case 0:
				break;
			case 1:
				carType = 0;
				break;
			case 2:
				houseType = 0;
				break;
			case 3:
				carType = 0;
				houseType = 0;
				break;
			default:
				break;
		}

		var vm = avalon.define({
			$id: 'assess-simple',
			data: [],
			level: '',
			params: {
				professional: professional,
				salary: salary,
				carType: carType,
				houseType: houseType
			},
			imgUrl: function (item) {
				return item.logo || 'http://img0.rongsue.com/images/channel/rec-logo.png';
			},
			productName: function (item) {
				return item.instName + '-' + item.name;
			},
			tags: function (item) {
				var list = [];
				var t = item.featuresText.split(',');
				$.each(item.features.split(','), function (i, str) {
					list.push('<span class="f' + str + '">' + t[i] + '</span>');
				})
				return list.join('');
			},
			info: function (item) {
				return '贷款最高' + item.loanMax + '万元，' + item.takeTimesText + '内放款，利率' + item.rateMin + '%';
			},
			desc: function (item) {
				return item.requirement;
			},
			result: function () {
				var data = vm.$model;
				util.ajax({
					url: '/assess/simple',
					type: 'post',
					data: data.params,
					success: function (rsp) {
						vm.level = rsp.data;
					}
				})
			},
			recommend: function () {
				var data = vm.$model;
				console.log(data);
				util.ajax({
					url: '/assess/simple/recommend',
					type: 'post',
					data: data.params,
					success: function (rsp) {
						vm.data = avalon.mix(true, [], rsp.data);
					}
				});
			}
		});

		vm.$watch('onReady', function () {
			vm.result(); // 获取评分结果
			vm.recommend(); // 获取推荐结果
		});

		avalon.scan(document.body);
	})
});